import 'package:flutter/material.dart';
import 'package:flutter_demo/baixing_page/HomeHeaderPage.dart';
import 'package:flutter_demo/pages/HomePage.dart';
import 'package:flutter_demo/pages/MyPage.dart';
import 'package:flutter_demo/pages/SearchPage.dart';
import 'package:flutter_demo/pages/TravelPage.dart';
import 'package:flutter_demo/pages/XyHomePage.dart';

class tabNavigator extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _tabNavigatorState();
}

// 固定写法
class _tabNavigatorState extends State<tabNavigator> {
  var _currentIndex = 0;
  final _defaultColor = Colors.grey;
  final _activeColor = Colors.blue;
  final _controller = PageController(initialPage: 0);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _controller,
        children: <Widget>[
          XyHomePage(),
          HomeHeaderFulPage(),
          MyPage(),
          SearchPage(),
          TravelPage()
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: _currentIndex,
          onTap: (index) {
            _controller.jumpToPage(index);
            setState(() {
              _currentIndex = index;
            });
          },
          items: [
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.home,
                  color: _defaultColor,
                ),
                activeIcon: Icon(
                  Icons.home,
                  color: _activeColor,
                ),
                title: Text("首页",
                    style: TextStyle(
                        color: _currentIndex == 0
                            ? _activeColor
                            : _defaultColor))),
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.search,
                  color: _defaultColor,
                ),
                activeIcon: Icon(
                  Icons.search,
                  color: _activeColor,
                ),
                title: Text("搜索",
                    style: TextStyle(
                        color: _currentIndex == 1
                            ? _activeColor
                            : _defaultColor))),
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.search,
                  color: _defaultColor,
                ),
                activeIcon: Icon(
                  Icons.search,
                  color: _activeColor,
                ),
                title: Text("卖闲置",
                    style: TextStyle(
                        color: _currentIndex == 2
                            ? _activeColor
                            : _defaultColor))),
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.camera_alt,
                  color: _defaultColor,
                ),
                activeIcon: Icon(
                  Icons.camera_alt,
                  color: _activeColor,
                ),
                title: Text("旅拍",
                    style: TextStyle(
                        color: _currentIndex == 3
                            ? _activeColor
                            : _defaultColor))),
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.account_circle,
                  color: _defaultColor,
                ),
                activeIcon: Icon(
                  Icons.account_circle,
                  color: _activeColor,
                ),
                title: Text("我的",
                    style: TextStyle(
                        color: _currentIndex == 4
                            ? _activeColor
                            : _defaultColor))),
          ]),
      floatingActionButton: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Stack(
            children: <Widget>[
              Center(
                child: Container(
                    width: 50,
                    height: 10,
                    margin: EdgeInsets.only(top: 50),
                    decoration: BoxDecoration(
                      color: Colors.red,
                    ),
                    child: Text(
                      "超多人想买",
                      style: TextStyle(fontSize: 10, color: Colors.red),
                    )),
              ),
              Center(
                child: Container(
                    width: 60,
                    margin: EdgeInsets.only(bottom: 0),
                    decoration: BoxDecoration(
                      color: Colors.white,
                      shape: BoxShape.circle,
                    ),
                    child: Container(
                      margin: EdgeInsets.all(5),
                      decoration: BoxDecoration(),
                      child: FloatingActionButton(
                        backgroundColor: Colors.yellow,
                        onPressed: () {
                          setState(() {
                            _controller.jumpToPage(2);
                            setState(() {
                              _currentIndex = 2;
                            });
                          });
                        },
                        child: Center(
                          child: Icon(Icons.add),
                        ),
                      ),
                    )),
              ),
              Center(
                  child: Container(
                    margin: EdgeInsets.only(top: 54),
                  decoration: BoxDecoration(
                    color: Colors.red,
                    borderRadius: BorderRadius.only(bottomLeft: Radius.circular(5), bottomRight: Radius.circular(5))
                  ),
                child: Text(
                  "超多人想买",
                  style: TextStyle(fontSize: 10, color: Colors.white),
                ),
              ))
            ],
          )
        ],
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }
}
